package com.platform.admin.exception;

import cn.hutool.core.util.StrUtil;
import com.platform.common.entity.ApiResponseCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @Description: 自定义异常
 * @author: yuanlai
 * @CreateTime: 2022/5/18 10:16
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class XxxRuntimeException extends RuntimeException {
    private ApiResponseCode apiResponseCode;
    private String message;

    /**
     * Constructs a new runtime exception with {@code null} as its
     * detail message.  The cause is not initialized, and may subsequently be
     * initialized by a call to {@link #initCause}.
     */
    public XxxRuntimeException(ApiResponseCode apiResponseCode) {
        this.apiResponseCode = apiResponseCode;
        this.message = apiResponseCode.getMessage();
    }

    /**
     * 可变参支持
     *
     * @param apiResponseCode api响应代码
     * @param paramValues     param值
     */
    public XxxRuntimeException(ApiResponseCode apiResponseCode, String... paramValues) {
        this.apiResponseCode = apiResponseCode;
        apiResponseCode.setMessage(StrUtil.format(apiResponseCode.getMessage(), paramValues));
        this.message = apiResponseCode.getMessage();
    }
}
